package com.sh;


import com.sh.Utils.MyLoader;
import com.sh.bean.BankMarketing_my;
import com.sh.bean.MySample;
import com.sh.group.ParallelGroupKnnClassifier_My;

import java.util.List;

public class Test_My {
    public static void main(String[] args) {
//        String trainPath = System.getProperty("user.dir")+"\\src\\main\\java\\com\\yc\\thread\\my_knn\\data\\bank.data";
//        String testPath = System.getProperty("user.dir")+"\\src\\main\\java\\com\\yc\\thread\\my_knn\\data\\bank.test";
        String trainPath = System.getProperty("user.dir") + "\\DIY_Knn\\src\\main\\java\\com\\sh\\data\\bank.data";
        String testPath = System.getProperty("user.dir")+"\\DIY_Knn\\src\\main\\java\\com\\sh\\data\\bank.test";
        List<BankMarketing_my> train = MyLoader.myLoad(trainPath);
        List<BankMarketing_my> test = MyLoader.myLoad(testPath);
        System.out.println("train size:"+train.size());
        System.out.println("test size:"+test.size());
        int k = 10;

        int processors = Runtime.getRuntime().availableProcessors();

        ParallelGroupKnnClassifier_My parallelGroupKnnClassifierMy = new ParallelGroupKnnClassifier_My(k, processors, true, train);

        long start ,end;
        int success = 0;
        int mistake = 0;
        start = System.currentTimeMillis();
        for (MySample bankMarketingMy : test) {
            String tag = parallelGroupKnnClassifierMy.classify(bankMarketingMy);
            if (tag.equals(bankMarketingMy.getTag())) {
                success++;
            }else {
                mistake++;
            }
        }
        end = System.currentTimeMillis();
        System.out.println("正确率：" + success * 100 / (success + mistake) + "%");
        System.out.println("耗时：" + (end - start) / 1000 + "s");

    }
}
